package com.example.composite.demo.safe.tree;

import com.example.composite.demo.safe.dir.Directory;

import java.util.LinkedList;
import java.util.List;

/**
 * 非叶子节点
 */
public class Node extends NodeComponent {

    private String name;
    private Integer level;

    public Node(String name, Integer level) {
        this.name = name;
        this.level = level;
    }

    private List<NodeComponent> nodes = new LinkedList<>();

    @Override
    public void showInfo() {
        System.out.println(this.name);
        for (NodeComponent node : this.nodes) {
            if (this.level != null) {
                for (int i = 0; i < this.level; i++) {
                    System.out.print("\t");
                }
                for (int i = 0; i < this.level; i++) {
                    //每一行开始打印一个+号
                    if (i == 0) {
                        System.out.print("+");
                    }
                    System.out.print("-");
                }
                System.out.print(" ");
            }
            node.showInfo();
        }
    }

    public void addNode(NodeComponent nodeComponent) {
        nodes.add(nodeComponent);
    }

    public void removeNode(NodeComponent nodeComponent) {
        nodes.remove(nodeComponent);
    }


}
